import React from "react";
import { Button, Select, Space, Image } from "antd";
import { prodListApi } from "@/api";
import AliOssViewImage from "@/ui/xx-AliyunOSSUpload/AliOssViewImage";

/**@description 列表表格字段 */
const getColumns = ({ open = Function, handleDelete = Function }) => {
    const columns = [
        {
            title: "商品编号",
            key: "productId",
            dataIndex: "productId",
            width: 100,
        },
        {
            title: "商品信息",
            key: "product",
            dataIndex: "product",
            width: 380,
            render: (text, record) => {
                const { masterImages } = record;
                const list = JSON.parse(masterImages);
                // const fileName = (JSON.parse(masterImages))[0].name
                return (
                    <Space>
                        {/* <AliOssViewImage
                            width={60}
                            fileName={fileName}
                        /> */}
                        <Image
                            preview={false}
                            width={60}
                            height={60}
                            src={list[0].url} />
                        <div>
                            {record.title}
                        </div>
                    </Space>
                )
            }
        },
        {
            title: "价格",
            key: "price",
            dataIndex: "price",
            width: 100
        },
        {
            title: "销量",
            key: "salesCount",
            dataIndex: "salesCount",
            width: 100
        },
        {
            title: "库存",
            key: "stock",
            dataIndex: "stock",
            width: 100
        },
        {
            title: "排序",
            key: "sort",
            dataIndex: "sort",
            width: 100
        },
        {
            title: "销售状态",
            key: "status",
            dataIndex: "status",
            width: 100
        },
        {
            title: "创建时间",
            key: "createTime",
            dataIndex: "createTime",
            width: 200
        },
        {
            title: "操作",
            key: "action",
            width: 200,
            fixed: "right",
            dataIndex: "action",
            render: (text, record) => (<>
                <Space>
                    <Button type="link" onClick={() => open({ type: "update", id: record.id })}>编辑</Button>
                    <Button type="link" danger onClick={() => handleDelete(record)}>删除</Button>
                </Space>
            </>)
        },
    ];
    return columns;
}

export default getColumns;